package com.stone.persistent.recyclerview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.stone.persistent.recyclerview.R;

import org.jetbrains.annotations.NotNull;


public class MenuGridAdapter extends RecyclerView.Adapter<MenuGridAdapter.MenuViewHolder> {
    private LayoutInflater inflater;
    private String[] MENU_TITLES;
    private Integer[] MENU_ICONS;

    private final void buildData(int page) {
        if (page == 0) {
            this.MENU_TITLES = new String[]{"京东超市", "数码电器", "京东服饰", "免费水果", "京东到家", "充值缴费", "9.9元拼", "领券", "赚钱", "PLUS会员"};
            this.MENU_ICONS = new Integer[]{
                    R.mipmap.menu_icon01,
                    R.mipmap.menu_icon02,
                    R.mipmap.menu_icon03,
                    R.mipmap.menu_icon04,
                    R.mipmap.menu_icon05,
                    R.mipmap.menu_icon06,
                    R.mipmap.menu_icon07,
                    R.mipmap.menu_icon08,
                    R.mipmap.menu_icon09,
                    R.mipmap.menu_icon10};
        } else {
            this.MENU_TITLES = new String[]{"京东国际", "京东拍卖", "唯品会", "沃尔玛", "京东旅行", "看病购药", "拍拍二手", "分享赚钱", "京东生鲜", "更多频道"};
            this.MENU_ICONS = new Integer[]{    R.mipmap.menu_icon11,
                    R.mipmap.menu_icon12,
                    R.mipmap.menu_icon13,
                    R.mipmap.menu_icon14,
                    R.mipmap.menu_icon15,
                    R.mipmap.menu_icon16,
                    R.mipmap.menu_icon17,
                    R.mipmap.menu_icon18,
                    R.mipmap.menu_icon19,
                    R.mipmap.menu_icon20};
        }
    }

    @NotNull
    public MenuViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
        View itemView = this.inflater.inflate(R.layout.item_menu, parent, false);
        return new MenuViewHolder(itemView);
    }




    @Override
    public void onBindViewHolder(MenuViewHolder holder, int position) {
        ImageView var3 = (ImageView) holder.itemView.findViewById(R.id.item_menu_icon);
        var3.setImageResource(MENU_ICONS[position]);
        TextView var4 = (TextView) holder.itemView.findViewById(R.id.item_menu_title);
        var4.setText(MENU_TITLES[position]);
    }




    public int getItemCount() {
        return MENU_TITLES.length;
    }

    public MenuGridAdapter(@NotNull Context context, int page) {
         inflater = LayoutInflater.from(context);
        this.buildData(page);
    }

    public final class MenuViewHolder extends RecyclerView.ViewHolder {

        public MenuViewHolder(@NotNull View itemView) {
            super(itemView);
        }
    }
}